﻿using System.Collections.Specialized;
using Newtonsoft.Json;

namespace CometDocs
{
    internal partial class Client
    {
        /// <summary>
        /// Get the current state of a conversion: https://www.cometdocs.com/developer/apiDocumentation#method-getConversionStatus
        /// </summary>
        /// <param name="token">A valid authentication token.</param>
        /// <param name="file">A file.</param>
        /// <param name="conversion">A conversion type.</param>
        /// <returns>A conversion status.</returns>
        public ConversionStatus GetConversionStatus(AuthenticationToken token, FileInfo file, ConversionType conversion)
        {
            NameValueCollection @params = new NameValueCollection(3);
            @params.Add("token", token.Value);
            @params.Add("fileId", file.ID.ToString());
            @params.Add("conversionType", conversion.ToString());

            byte[] result = webClient.UploadValues(APIRoot + "getConversionStatus", @params);

            string json = encoding.GetString(result);

            GetConversionStatusResponse response = JsonConvert.DeserializeObject<GetConversionStatusResponse>(json);

            CheckAndThrow(response);

            return response.ConversionStatus;
        }
    }
}
